﻿using System;
using System.Collections.Generic;
using Volo.Abp;

namespace mozhi.smarterp.Finance.Basedatas
{
    public class PrintTemplate : AggregateRootBase<Guid>
    {
        public string Name { get; private set; }

        public string ModuleCode { get; private set; }

        public Guid TemplateFileId { get; private set; }

        public Guid? ImageFileId { get; private set; }

        private PrintTemplate() { }

        public PrintTemplate(Guid id, string name, string moduleCode, Guid templateFileId, Guid? imageFileId)
        {
            Id = id;
            Name = name;
            ModuleCode = moduleCode;
            TemplateFileId = templateFileId;
            ImageFileId = imageFileId;

            Validate();
        }

        public void ChangeName(string name)
        {
            Name = name;

            Validate();
        }

        public void ChangeFile(Guid templateFileId, Guid? imageFileId)
        {
            TemplateFileId = templateFileId;
            ImageFileId = imageFileId;

            Validate();
        }


        #region
        private void Validate()
        {
            if (TemplateFileId == default)
                throw new UserFriendlyException("模板文件不能为空", "100000");

            if (Name.IsNullOrEmpty())
                throw new UserFriendlyException("模板名称不能为空", "100000");

            if (ModuleCode.IsNullOrEmpty())
                throw new UserFriendlyException("模板所属模块不能为空", "100000");

        }
        #endregion
    }
}
